﻿'use strict';

/**
 * Config for the router
 */
angular.module('app')
  .run(
    ['$rootScope', '$state', '$stateParams',
      function ($rootScope, $state, $stateParams) {
          $rootScope.$state = $state;
          $rootScope.$stateParams = $stateParams;
      }
    ]
  )
  .config(
    ['$stateProvider', '$urlRouterProvider',
      function ($stateProvider, $urlRouterProvider) {

          $urlRouterProvider
              .otherwise('/app/dashboard-v1');
          $stateProvider
              .state('app', {
                  abstract: true,
                  url: '/app',
                  templateUrl: 'tpl/app.html'
              })
              .state('app.dashboard-v1', {
                  url: '/dashboard-v1',
                  templateUrl: 'tpl/app_dashboard_v1.html',
                  resolve: {
                      deps: ['$ocLazyLoad',
                        function ($ocLazyLoad) {
                            return $ocLazyLoad.load(['js/controllers/chart.js']);
                        }]
                  }
              })
              .state('app.dashboard-v2', {
                  url: '/dashboard-v2',
                  templateUrl: 'tpl/app_dashboard_v2.html',
                  resolve: {
                      deps: ['$ocLazyLoad',
                        function ($ocLazyLoad) {
                            return $ocLazyLoad.load(['js/controllers/chart.js']);
                        }]
                  }
              })
              .state('app.enterprise', {
                  url: '/enterprise',
                  templateUrl: 'tpl/app/enterprise/index.html'
              })
              .state('app.org', {
                  url: '/org',
                  templateUrl: 'tpl/app/org/index.html'
              })
              .state('app.orgpermission', {
                  url: '/orgpermission',
                  templateUrl: 'tpl/app/orgpermission/index.html'
              })
              .state('app.orgfunction', {
                  url: '/orgfunction',
                  templateUrl: 'tpl/app/orgfunction/index.html'
              })
              .state('app.dept', {
                  url: '/dept',
                  templateUrl: 'tpl/app/dept/index.html',
                  resolve: {
                      deps: ['$ocLazyLoad',
                        function ($ocLazyLoad) {
                            return $ocLazyLoad.load('tpl/app/dept/ctrl.js');
                        }]
                  }
              })
              .state('app.role', {
                  url: '/role',
                  templateUrl: 'tpl/app/role/index.html'
              })
              .state('app.userpermission', {
                  url: '/userpermission',
                  templateUrl: 'tpl/app/userpermission/index.html'
              })
              .state('app.usergroup', {
                  url: '/usergroup',
                  templateUrl: 'tpl/app/usergroup/index.html'
              })
              .state('app.demo_datatable', {
                  url: '/demo_datatable',
                  templateUrl: 'tpl/app/demo_datatable/index.html',
                  resolve: {
                      deps: ['$ocLazyLoad',
                        function ($ocLazyLoad) {
                            return $ocLazyLoad.load('tpl/app/demo_datatable/ctrl.js');
                        }]
                  }
              })
            .state('app.demo_datatablepaging', {
                url: '/demo_datatablepaging',
                templateUrl: 'tpl/app/demo_datatablepaging/index.html',
                resolve: {
                    deps: ['$ocLazyLoad',
                      function ($ocLazyLoad) {
                          return $ocLazyLoad.load('tpl/app/demo_datatablepaging/ctrl.js');
                      }]
                }
            })
      }
    ]
  );